<template>
    <Modal v-model="modal.show" width="180" :title="modal.title" @on-ok="ok" @on-cancel="cancel">
        <space direction="vertical">
            <Input v-model="modal.funcName" placeholder="功能名称" style="width: 150px" />
            <Input v-model="modal.url" placeholder="接口地址" style="width: 150px" />
        </space>
    </Modal>
</template>
<script setup>
import { reactive } from "vue";
import http from '@/util/http'
let { proxy } = getCurrentInstance();
const emit = defineEmits(['initFunc'])
const modal = reactive({ show: false, title: "", funcName: "", url: "", funcID: "" });
const show = (funcID) => {
    modal.show = true;
    if (funcID === '') {
        modal.title = "添加功能"
    } else {
        modal.title = "编辑功能"
        http.get("/Basic/Func/Detail?id=" + funcID, {}, (response) => {
            modal.funcID = response.data.data.funcID
            modal.url = response.data.data.url
            modal.funcName = response.data.data.name
        });
    }
}
const ok = () => {
    http.post("/Basic/Func/AddOrUpdate", { name: modal.funcName, url: modal.url, funcID: modal.funcID }, (response) => {
        if (response.data.flag) {
            emit('initFunc');
            proxy.$Message.success(response.data.msg);
        } else {
            proxy.$Message.error(response.data.msg);
        }
    });
}
defineExpose({
    show,
});
</script>